﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:BookReader" 
    xmlns:ucc="clr-namespace:BookReader.Controls">
    
    <local:BookmarkToVisibilityConverter x:Key="BookmarkToVisibilityConverter"/>
    
    <!-- TOOLTIP style and associated datatemplate -->
    <Style x:Key="TransparentToolTipStyle" TargetType="{x:Type ToolTip}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ToolTip}">
                    <Border >
                        <ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <DataTemplate x:Key="BookToolTipTemplate" DataType="{x:Type local:BaseBook}">
        <Grid >
            <Grid.Resources>
                <Style TargetType="{x:Type TextBlock}" x:Key="TextBlockBase">
                    <Setter Property="Foreground" Value="Silver"/>
                </Style>
                <Style TargetType="{x:Type TextBlock}" x:Key="{x:Type TextBlock}" BasedOn="{StaticResource TextBlockBase}">
                </Style>
                <Style TargetType="{x:Type TextBlock}" x:Key="Data" BasedOn="{StaticResource TextBlockBase}">
                    <Setter Property="Foreground" Value="White"/>
                    <Setter Property="FontWeight" Value="Bold"/>
                </Style>
            </Grid.Resources>
            <Border Padding="2,2,2,2" CornerRadius="8" BorderBrush="#40000000" BorderThickness="2">
                <Border CornerRadius="6" ClipToBounds="True" Padding="6,6,6,6">
                    <Border.Background>
                        <LinearGradientBrush EndPoint="0.75,0.319" StartPoint="0.213,0.672">
                            <GradientStop Color="#99000000"/>
                            <GradientStop Color="#EA000000" Offset="1"/>
                        </LinearGradientBrush>
                    </Border.Background>
					<Grid>
						<Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="80"/>
                                    <ColumnDefinition Width="Auto"/>
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition />
                                    <RowDefinition />
									<RowDefinition />
                                </Grid.RowDefinitions>
								<TextBlock Grid.Column="1" Grid.Row="0" Text="{Binding Path=FileName}" FontSize="14" DockPanel.Dock="Left" Style="{StaticResource Data}" />
								<TextBlock Grid.Column="1" Grid.Row="1" Text="{Binding Path=FilePath}" />
								<Image Grid.Column="0" Grid.RowSpan="3" Source="{Binding Path=Cover}" Width="70"/>
								<Grid Grid.Column="1" Grid.Row="2">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="12" />
                                    <ColumnDefinition Width="Auto"/>
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition />
                                    <RowDefinition />
                                </Grid.RowDefinitions>
                                <TextBlock Grid.Column="0" Grid.Row="0" Text="File size:" />
                                <TextBlock Grid.Column="2" Grid.Row="0" Text="{Binding Path=Size}"  Style="{StaticResource Data}"/>
                                <TextBlock Grid.Column="0" Grid.Row="1" Text="Page count:" />
                                <TextBlock Grid.Column="2" Grid.Row="1" Text="{Binding Path=NbPages}"  Style="{StaticResource Data}"/>
                            </Grid>
					</Grid>
                </Border>
            </Border>
        </Grid>
    </DataTemplate>
    <!-- END TOOLTIP -->
    
    <!-- CATALOG style and associated datatemplate -->
    <Style x:Key="CatalogCoverStyle" TargetType="{x:Type ListBox}">
        <!-- Swap out the default items panel with a WrapPanel so that
           the images will be arranged with a different layout. -->
        <Setter Property="ItemsPanel">
            <Setter.Value>
                <ItemsPanelTemplate>
                    <WrapPanel />
                </ItemsPanelTemplate>
            </Setter.Value>
        </Setter>
        <!-- Set this attached property to 'Disabled' so that the 
           ScrollViewer in the ListBox will never show a horizontal 
           scrollbar, and the WrapPanel it contains will be constrained 
           to the width of the ScrollViewer's viewable surface. -->
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled" />
    </Style>

    <!-- Style for an individual generic item -->
    <Style TargetType="{x:Type ListBoxItem}">
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ListBoxItem}" >
                    <Border SnapsToDevicePixels="True" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" 
                            Background="{TemplateBinding Background}">
                        <ContentPresenter />
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter Property="Background" Value="#445B6249"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <DataTemplate x:Key="PublicTemplate" DataType="{x:Type local:BaseBook }">
        <Grid Margin="5">
            <Grid.RowDefinitions>
                <RowDefinition Height="0.9*"/>
                <RowDefinition Height="0.1*"/>
            </Grid.RowDefinitions>
            <!-- Image Template -->
            <Border x:Name="BorderStatus" BorderThickness="6" CornerRadius="5" Margin="0">
                <Grid>
                    <Image x:Name="CoverImage" Source="{Binding Path=Cover}" Width="70" Margin="0">
                        <Image.ToolTip>
                            <ToolTip Style="{DynamicResource TransparentToolTipStyle}">
                                <ContentControl Content="{Binding}" ContentTemplate="{StaticResource BookToolTipTemplate}"/>
                            </ToolTip>
                        </Image.ToolTip>
                    </Image>
                    <Image Source="..\Images\TheRedPushPin.png" Height="30" HorizontalAlignment="Right" VerticalAlignment="Top"
					Visibility="{Binding Path=Bookmark, Converter={StaticResource BookmarkToVisibilityConverter}}" Grid.RowSpan="2"></Image>
                </Grid>
            </Border>
            <ucc:RatingControl Grid.Row="1" HorizontalAlignment="Stretch" Height="15"></ucc:RatingControl>
        </Grid>
        <DataTemplate.Triggers>
            <DataTrigger Binding="{Binding Path=IsSecured}" Value="True">
                <Setter TargetName="CoverImage" Property="Source" Value="..\Images\Forbidden.png" />
            </DataTrigger>
            <DataTrigger Binding="{Binding Path=IsRead}" Value="True">
                <Setter TargetName="BorderStatus" Property="BorderBrush" Value="Red"  />
            </DataTrigger>
        </DataTemplate.Triggers>
    </DataTemplate>

</ResourceDictionary>